package com.bungarus.smart.busi;

import com.bungarus.config.ChannelServerInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class ChannelSmartHandlerInitializer extends ChannelServerInitializer {
    private final Scanner scanner;
    private final String host;

    private static final int ALL_IDLE_TIMEOUT = 5;

    public ChannelSmartHandlerInitializer(Scanner scanner, String host) {
        this.scanner = scanner;
        this.host = host;
    }

    @Override
    protected void initServerServiceHandlers(SocketChannel socketChannel) {
    }

    @Override
    protected void initNormalHandlers(SocketChannel socketChannel) {
        socketChannel.pipeline().addLast(new IdleStateHandler(0,
                0, ALL_IDLE_TIMEOUT, TimeUnit.SECONDS));
        socketChannel.pipeline().addLast(new ProcessMessageHandler());
        socketChannel.pipeline().addLast(new ClientHeartbeatHandler(scanner, host));
    }
}
